﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.SystemManager;

namespace CubicFWNet.Application.SystemManager
{
    public class StorageApp
    {
        private readonly StorageRepository _service = new StorageRepository();

        public List<Storage> GetList()
        {
            return _service.IQueryable().OrderBy(o => o.SortNo).ToList();
        }

        public Storage GetByName(string name)
        {
            return _service.IQueryable().FirstOrDefault(a=>a.Name == name);
        }

        public Storage GetForm(int id)
        {
            return _service.FindEntity(id);
        }

        public int AddOrUpdate(Storage entity)
        {
            if (entity.Id == 0)
            {
                //entity.Id = Guid.NewGuid();
                return _service.Insert(entity);
            }
            else
            {
                return _service.Update(entity);
            }
        }

        public int Delete(int id)
        {
            var entity = _service.FindEntity(e => e.Id == id);
            if (entity == null)
                return -404;
            return _service.Delete(entity);
        }


    }
}
